<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>宜鲜生</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <!-- load css -->
    <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css?v=v3.3.7" media="all">
    <link rel="stylesheet" type="text/css" href="../css/font/iconfont.css?v=1.0.0" media="all">
    <link rel="stylesheet" type="text/css" href="../css/layui.css?v=1.0.9" media="all">
    <link rel="stylesheet" type="text/css" href="../css/main.css?v1.3.4" media="all">
    <link rel="stylesheet" type="text/css" href="../css/autocomplete.css" media="all">

    <style>
        .layui-form-select dl{
            z-index: 19900810;
        }
    </style>
</head>
<body>
<div class="container-fluid larry-wrapper">
    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12">
            <!--头部搜索-->
            <section class="panel panel-padding">
                <form class="layui-form" action="/education/admin/product">
                    <div class="layui-form">
                        <div class="layui-inline">
                            <select name="_query.status" id="status">
                                <option value="">商品状态</option>
                                <option value="1">上架</option>
                                <option value="2">预售</option>
                                <option value="0">下架</option>
                            </select>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input class="layui-input" name="_query.keyword" placeholder="关键字">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button lay-submit class="layui-btn" lay-filter="search">查找</button>
                        </div>
                    </div>
                </form>
            </section>

            <!--列表-->
            <section class="panel panel-padding">
                <div class="group-button">
                    <button class="layui-btn layui-btn-small modal-catch" beforeFun="beforeAdd"
                            data-params='{"content":".add-subcat", "title":"添加","type":"1", "full":"true", "maxmin":"true"}'>
                        <i class="iconfont">&#xe649;</i> 添加
                    </button>
                    <button class="layui-btn layui-btn-small layui-btn-danger ajax-all" data-name="checkbox" data-params='{"url": "/education/admin/product/delete"}'>
                        <i class="iconfont">&#xe626;</i> 删除
                    </button>
                    <button class="layui-btn layui-btn-small layui-btn-normal ajax-all" data-name="checkbox"
                            data-params='{"url": "/education/admin/marquee/save","data": "type=1", "confirm":"true"}'>
                        <i class="iconfont">&#xe654;</i> 推送至轮播图
                    </button>
                    <button class="layui-btn layui-btn-small layui-btn-normal ajax-all" data-name="checkbox"
                            data-params='{"url": "/education/admin/top/save", "data": "type=1","confirm":"true"}'>
                        <i class="iconfont">&#xe654;</i> 推送至首页
                    </button>
                </div>
                <div id="list" class="layui-form"></div>

                <div class="text-right" id="page"></div>
            </section>
        </div>
    </div>
</div>
<div class="add-subcat">
    <!--#include file="product-form.html"-->
</div>


</body>
<!--#include file="product-list.html"-->
<script src="../js/layui/layui.js"></script>
<script type="text/javascript" src="../js/lib/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../js/lib/rest.js"></script>
<script type="text/javascript" src="../../jsfile/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="../../jsfile/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="../js/lib/bootstrap.autocomplete.js"></script>
<!--#include file="common/version.html"-->
<script>
    layui.use('user_list');

    layui.use(['jquery','upload'], function(exports) {
        var box;
        //上传文件设置
        layui.upload({
            elem: '.layui-upload-file',
            url: '/education/api/image/product',
            before: function (input) {
                box = $(input).parent('form').parent('div').parent('.layui-input-block');
                if (box.next('div').length > 0) {
                    box.next('div').html('<div class="imgbox"><p>上传中...</p></div>');
                } else {
                    box.after('<div class="layui-input-block"><div class="imgbox"><p>上传中...</p></div></div>');
                }
            },
            success: function (res) {
                if (res.code == 200) {
                    box.next('div').find('div.imgbox').html('<img src="/education' + res.data[0].url + '" alt="..." class="img-thumbnail">');
                    box.find('input[name=cover_image]').val(res.data[0].url);
                } else {
                    box.next('div').find('p').html('上传失败...')
                }
            }
        });
    });

    layui.use(['form'], function () {
        var form = layui.form();
        form.on('select(statusChange)', function(data){
            if(data.value == '2'){
                $('#preTime1').show();
                $('#preTime2').show();
            }else {
                $('#preTime1').hide();
                $('#preTime2').hide();
            }
        });
    });

    function initData(){
        var ue = UE.getEditor('container');
        ue.addListener('fullscreenchanged',function(event,isFullScreen){
            if(isFullScreen){
                $('.layui-layer-shade').remove();
            }
        });
        restPost('/education/admin/tag', null, function (rs) {
            if(rs.status == 200){
                var arr = ['<option value= > </option>'];
                for(var i=0; i<rs.data.list.length; i++){
                    var it = '<option value={v} >{s}</option>'.replace('{v}', rs.data.list[i].id)
                        .replace('{s}', rs.data.list[i].tag_name)
                    arr.push(it)
                }
                $('#tagId').html(arr.join(''));
            }
        });

        restPost('/education/api/dict', {type:'product.mark_code'}, function (rs) {console.log(rs)
            if(rs.code == 200){
                var arr = [];
                for(var i=0; i<rs.data.length; i++){
                    var it =
                        '<input type="checkbox" name="mark_code-\'{c}\'" value="{c}" lay-skin="primary" title="{v}">'
                            .replace(/{c}/g, rs.data[i].code)
                            .replace('{v}', rs.data[i].value)
                    arr.push(it)
                }
                $('#markCode').html(arr.join(''));
            }
        });

        /*restPost('/education/admin/rebate', {}, function(rs){
            if(rs.status == 200){
                var arr = ['<option value=" ">----</option>'];
                $.each(rs.data.list, function(i, n){
                    var t = n.normal_rate1 +'|' + n.vip_rate1 + '|' + n.normal_rate2 +'|' +n.vip_rate2;
                    arr.push('<option value="'+ n.id +'">'+ n.name +'(' + t + ')' +'</option>')
                });
                $('#rebateId').html(arr.join(''));
            }
        });*/
        /*restPost('/education/api/freightTemplate', {}, function(rs){console.log(rs)
            if(rs.code == 200){
                var arr = [];
                $.each(rs.data, function(i, n){
                    arr.push('<option value="'+ n.id +'">'+ n.template_name +'</option>')
                });
                $('#templateId').html(arr.join(''));
            }
        });*/
    }

    function beforeAdd(obj){
        $('.imgbox').children().remove();
        $('#form1').attr('action', '/education/admin/product/save');
    }

    function _edit(ids) {
        var index = layer.open({
            type: 1,
            title:'编辑',
            content: $('.add-subcat')
        });
        layer.full(index);
        $('.imgbox').children().remove();
        $('#form1 input[type=checkbox]').prop('checked', false);
        $('#form1').attr('action', '/education/admin/product/update/' + ids);

        var ue = UE.getEditor('container');
        restGet('/education/admin/product/view/' + ids, null, $('#form1'), function(rs){
            if(rs.code == 200 || rs.status == 200){
                var str =  '<img src="/education{src}" alt="..." class="img-thumbnail" style="width: 200px;">';
                var imgDiv = $('input[name=cover_image]').parent().next().children('.imgbox');
                imgDiv.append(str.replace('{src}', rs.data.cover_image));

                ue.ready(function() {
                    //设置编辑器的内容
                    ue.setContent(rs.data.description);
                });
                layui.form().render('checkbox');

            }
        })
    }

    function _picManage(ids, name){
        var index = layer.open({
            type: 2,
            content: "productImage.html?ids=" + ids, "title": '【'+ name +"】图片管理", "full":"true"
        });
        layer.full(index);
    }

    function _commentManage(ids, name){
        var index = layer.open({
            type: 2,
            content: "productComment.html?ids=" + ids, "title": '【'+ name +"】评价管理", "full":"true"
        });
        layer.full(index);
    }

    function _skuManage(ids, name){
        var index = layer.open({
            type: 2,
            content: "productSku.html?ids=" + ids, "title": '【'+ name +"】规格管理", "full":"true"
        });
        layer.full(index);
    }

    function afterTableLoad(data) {
        layui.use(['jquery', 'jqmenu'], function(exports) {
            var jqmenu = layui.jqmenu;
            var menu = new jqmenu();
            menu.menuBind();
        });
    }
</script>
</html>